One Hat Cyber Team
Your IP :
104.23.243.58
Server IP :
104.21.51.23
Server :
Linux 128-201-239-36.cprapid.com 3.10.0-1160.41.1.el7.x86_64 #1 SMP Tue Aug 31 14:52:47 UTC 2021 x86_64
Server Software :
Apache
PHP Version :
7.4.33
Buat File
|
Buat Folder
Eksekusi
Dir :
~
/
home
/
juscatamarca
/
www
/
asuetos-feriados
/
public
/
View File Name :
holidays_edit.php
<?php require_once __DIR__ . '/../app/auth.php'; $me = current_user(); if (!$me) { header('Location: ' . base_url() . '/login.php'); exit; } if ($me['role'] !== 'admin') { header('Location: ' . base_url() . '/index.php'); exit; } require_once __DIR__ . '/../app/config.php'; $id = isset($_GET['id']) ? (int)$_GET['id'] : 0; if ($id <= 0) { header('Location: ' . base_url() . '/index.php'); exit; } $stmt = $pdo->prepare("SELECT * FROM holidays WHERE id = ?"); $stmt->execute([$id]); $evento = $stmt->fetch(); if (!$evento) { exit('Evento no encontrado.'); } $mensaje = ''; $errores = []; function valid_date($s) { return preg_match('/^\d{4}-\d{2}-\d{2}$/', $s); } if ($_SERVER['REQUEST_METHOD'] === 'POST') { $titulo = trim($_POST['titulo'] ?? ''); $tipo = strtoupper(trim($_POST['tipo'] ?? '')); $scope = trim($_POST['scope'] ?? ''); $desc = trim($_POST['descripcion'] ?? ''); $start = trim($_POST['start_date'] ?? ''); $end = trim($_POST['end_date'] ?? ''); $recur = isset($_POST['is_recurring']) ? 1 : 0; $color = trim($_POST['color'] ?? '#0d6efd'); if ($titulo === '') $errores[] = 'Título es obligatorio'; if (!in_array($tipo, ['FERIADO', 'ASUETO'], true)) $errores[] = 'Tipo inválido'; if (!valid_date($start)) $errores[] = 'Fecha desde inválida (YYYY-MM-DD)'; if ($end !== '' && !valid_date($end)) $errores[] = 'Fecha hasta inválida (YYYY-MM-DD)'; if (!$errores) { try { $stmt = $pdo->prepare(" UPDATE holidays SET title = ?, type = ?, scope = ?, description = ?, start_date = ?, end_date = ?, is_recurring = ?, color = ? WHERE id = ? "); $stmt->execute([ $titulo, $tipo, $scope ?: null, $desc ?: null, $start, $end ?: null, $recur, $color ?: '#0d6efd', $id ]); // Refrescar datos en memoria para mostrar en el form $stmt2 = $pdo->prepare("SELECT * FROM holidays WHERE id = ?"); $stmt2->execute([$id]); $evento = $stmt2->fetch(); $mensaje = '✅ Evento actualizado.'; } catch (Throwable $e) { $errores[] = 'Error al actualizar: ' . $e->getMessage(); } } } ?> <!doctype html> <html lang="es"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <title>Editar feriado/asueto — Asuetos & Feriados</title> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet"> </head> <body class="bg-light"> <nav class="navbar navbar-expand-lg bg-white border-bottom"> <div class="container-fluid"> <a class="navbar-brand" href="<?= base_url() ?>/index.php">Asuetos & Feriados</a> <div class="ms-auto d-flex align-items-center gap-2"> <span class="text-muted me-2"><?= htmlspecialchars($me['name']) ?></span> <a class="btn btn-outline-secondary btn-sm" href="<?= base_url() ?>/logout.php">Salir</a> </div> </div> </nav> <div class="container my-4"> <h3>Editar feriado/asueto</h3> <?php if ($mensaje): ?> <div class="alert alert-success"><?= htmlspecialchars($mensaje) ?></div> <?php endif; ?> <?php if ($errores): ?> <div class="alert alert-danger"> <ul class="mb-0"> <?php foreach ($errores as $e): ?><li><?= htmlspecialchars($e) ?></li><?php endforeach; ?> </ul> </div> <?php endif; ?> <form method="post" class="row g-3"> <div class="col-12"> <label class="form-label">Título *</label> <input type="text" name="titulo" class="form-control" value="<?= htmlspecialchars($evento['title'] ?? '') ?>" required> </div> <div class="col-md-4"> <label class="form-label">Tipo *</label> <select name="tipo" class="form-select" required> <option value="FERIADO" <?= (($evento['type'] ?? '') === 'FERIADO' ? 'selected' : '') ?>>Feriado</option> <option value="ASUETO" <?= (($evento['type'] ?? '') === 'ASUETO' ? 'selected' : '') ?>>Asueto</option> </select> </div> <div class="col-md-4"> <label class="form-label">Ámbito / Scope (opcional)</label> <input type="text" name="scope" class="form-control" value="<?= htmlspecialchars($evento['scope'] ?? '') ?>"> </div> <div class="col-md-4"> <label class="form-label">Color (opcional)</label> <input type="color" name="color" class="form-control form-control-color" value="<?= htmlspecialchars($evento['color'] ?? '#0d6efd') ?>"> </div> <div class="col-12"> <label class="form-label">Descripción (opcional)</label> <textarea name="descripcion" class="form-control" rows="3"><?= htmlspecialchars($evento['description'] ?? '') ?></textarea> </div> <div class="col-md-4"> <label class="form-label">Fecha desde *</label> <input type="date" name="start_date" class="form-control" value="<?= htmlspecialchars($evento['start_date'] ?? '') ?>" required> </div> <div class="col-md-4"> <label class="form-label">Fecha hasta (opcional)</label> <input type="date" name="end_date" class="form-control" value="<?= htmlspecialchars($evento['end_date'] ?? '') ?>"> </div> <div class="col-md-4 d-flex align-items-end"> <div class="form-check"> <input class="form-check-input" type="checkbox" name="is_recurring" id="rec" <?= !empty($evento['is_recurring']) ? 'checked' : '' ?>> <label class="form-check-label" for="rec">Repetir cada año</label> </div> </div> <div class="col-12 d-flex gap-2"> <button type="submit" class="btn btn-primary">Actualizar</button> <a href="<?= base_url() ?>/index.php" class="btn btn-secondary">Volver</a> </div> </form> </div> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/js/bootstrap.bundle.min.js"></script> </body> </html>