Primer subida completa
This commit is contained in:
139
public/admin/horarios.php
Executable file
139
public/admin/horarios.php
Executable file
@@ -0,0 +1,139 @@
|
||||
<?php
|
||||
if (!defined('BASE_PATH')) {
|
||||
define('BASE_PATH', dirname(__DIR__, 2));
|
||||
}
|
||||
require_once BASE_PATH . '/config/config.php';
|
||||
require_once BASE_PATH . '/src/Auth.php';
|
||||
require_once BASE_PATH . '/src/DiasHorarios.php';
|
||||
|
||||
$auth = new Auth();
|
||||
$auth->requireAdmin();
|
||||
|
||||
$horariosModel = new DiasHorarios();
|
||||
$message = '';
|
||||
$messageType = '';
|
||||
|
||||
$diasNombres = [
|
||||
'domingo' => 'Domingo',
|
||||
'lunes' => 'Lunes',
|
||||
'martes' => 'Martes',
|
||||
'miercoles' => 'Miércoles',
|
||||
'jueves' => 'Jueves',
|
||||
'viernes' => 'Viernes',
|
||||
'sabado' => 'Sábado'
|
||||
];
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$dia = $_POST['dia'] ?? '';
|
||||
$hora_apertura = $_POST["hora_apertura_$dia"] ?? '';
|
||||
$hora_cierre = $_POST["hora_cierre_$dia"] ?? '';
|
||||
$activo = isset($_POST["activo_$dia"]) ? 1 : 0;
|
||||
|
||||
if (empty($dia) || empty($hora_apertura) || empty($hora_cierre)) {
|
||||
$message = 'Todos los campos son obligatorios';
|
||||
$messageType = 'danger';
|
||||
} else {
|
||||
$horariosModel->update($dia, compact('hora_apertura', 'hora_cierre', 'activo'));
|
||||
$message = 'Horario actualizado correctamente';
|
||||
$messageType = 'success';
|
||||
}
|
||||
}
|
||||
|
||||
$horarios = $horariosModel->getAll();
|
||||
$currentPage = 'horarios';
|
||||
$pageTitle = 'Configuración de Horarios';
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="es">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Horarios - Contenedor Ibiza</title>
|
||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||
</head>
|
||||
<body>
|
||||
<?php include BASE_PATH . '/public/partials/navbar.php'; ?>
|
||||
|
||||
<div class="container mt-4">
|
||||
<h2 class="mb-4">Configuración de Horarios</h2>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<div class="alert alert-<?= $messageType ?>"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="card shadow-sm">
|
||||
<div class="card-body">
|
||||
<form method="POST" id="horariosForm">
|
||||
<input type="hidden" name="dia" id="selectedDia" value="">
|
||||
|
||||
<div class="table-responsive">
|
||||
<table class="table table-hover mb-0">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Día</th>
|
||||
<th>Hora Apertura</th>
|
||||
<th>Hora Cierre</th>
|
||||
<th>Activo</th>
|
||||
<th>Acciones</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($horarios as $h): ?>
|
||||
<tr>
|
||||
<td><strong><?= $diasNombres[$h['dia_semana']] ?? $h['dia_semana'] ?></strong></td>
|
||||
<td>
|
||||
<input type="time" class="form-control form-control-sm"
|
||||
name="hora_apertura_<?= $h['dia_semana'] ?>"
|
||||
value="<?= $h['hora_apertura'] ?>" required>
|
||||
</td>
|
||||
<td>
|
||||
<input type="time" class="form-control form-control-sm"
|
||||
name="hora_cierre_<?= $h['dia_semana'] ?>"
|
||||
value="<?= $h['hora_cierre'] ?>" required>
|
||||
</td>
|
||||
<td>
|
||||
<div class="form-check form-switch">
|
||||
<input class="form-check-input" type="checkbox"
|
||||
name="activo_<?= $h['dia_semana'] ?>"
|
||||
id="activo_<?= $h['dia_semana'] ?>"
|
||||
<?= $h['activo'] ? 'checked' : '' ?>>
|
||||
</div>
|
||||
</td>
|
||||
<td>
|
||||
<button type="button" class="btn btn-sm btn-primary"
|
||||
onclick="guardarHorario('<?= $h['dia_semana'] ?>')">
|
||||
Guardar
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card mt-4 shadow-sm">
|
||||
<div class="card-header bg-secondary text-white">
|
||||
<h5 class="mb-0">Información</h5>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<ul class="mb-0">
|
||||
<li>Los días marcados como "Activo" aparecerán en los turnos.</li>
|
||||
<li>Los horarios pueden modificarse en cualquier momento.</li>
|
||||
<li>La hora de cierre debe ser posterior a la hora de apertura.</li>
|
||||
</ul>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
|
||||
<script>
|
||||
function guardarHorario(dia) {
|
||||
document.getElementById('selectedDia').value = dia;
|
||||
document.getElementById('horariosForm').submit();
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user