Mesmo padrão de horario/: extrai dia/abertura/fecho para _form.php. create.php formatava open/close sem substr() enquanto edit.php cortava para "HH:MM" com substr(..., 0, 5) por vir de uma coluna TIME da BD; unificado na versão de edit.php (sem efeito em create.php). Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
57 lines
2.2 KiB
PHP
57 lines
2.2 KiB
PHP
<?php
|
|
require __DIR__ . '/../../../config/db.php';
|
|
require __DIR__ . '/../../../config/functions.php';
|
|
$user = require_admin();
|
|
|
|
$id = (int) ($_GET['id'] ?? 0);
|
|
if (!$id) { header('Location: index.php'); exit; }
|
|
|
|
$item = db_whours_get($pdo, $id);
|
|
if (!$item) { header('Location: index.php'); exit; }
|
|
|
|
$errors = [];
|
|
$data = $item;
|
|
|
|
$dias = ['segunda'=>'Segunda','terça'=>'Terça','quarta'=>'Quarta','quinta'=>'Quinta','sexta'=>'Sexta','sabado'=>'Sábado','domingo'=>'Domingo','feriados'=>'Feriados'];
|
|
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|
csrf_check();
|
|
$data = [
|
|
'week_day' => trim($_POST['week_day'] ?? ''),
|
|
'open' => trim($_POST['open'] ?? ''),
|
|
'close' => trim($_POST['close'] ?? ''),
|
|
];
|
|
if ($data['week_day'] === '') $errors[] = 'O dia é obrigatório.';
|
|
if ($data['open'] === '') $errors[] = 'A hora de abertura é obrigatória.';
|
|
if ($data['close'] === '') $errors[] = 'A hora de fecho é obrigatória.';
|
|
|
|
if (!$errors) {
|
|
$changed = db_whours_update($pdo, $id, $data);
|
|
if ($changed) session()->setFlashdata('success', 'Horário atualizado.');
|
|
else session()->setFlashdata('warning', 'Nenhuma alteração.');
|
|
header('Location: ' . base_url('views/admin/work_hours/edit.php?id=' . $id));
|
|
exit;
|
|
}
|
|
}
|
|
|
|
$page_title = 'Editar Dia';
|
|
include __DIR__ . '/../../../includes/header.php';
|
|
?>
|
|
<div class="container" style="max-width:500px;">
|
|
<div class="d-flex justify-content-between align-items-center mb-4">
|
|
<h1 class="h3 mb-0">Editar Dia</h1>
|
|
<a class="btn btn-outline-secondary btn-sm" href="index.php"><i class="bi bi-arrow-left me-1"></i>Voltar</a>
|
|
</div>
|
|
<?php foreach ($errors as $e): ?><div class="alert alert-danger"><?= htmlspecialchars($e) ?></div><?php endforeach; ?>
|
|
|
|
<form method="POST" class="card shadow-sm"><div class="card-body">
|
|
<?= csrf_field() ?>
|
|
<?php include __DIR__ . '/_form.php'; ?>
|
|
<div class="mt-4 d-flex gap-2">
|
|
<button type="submit" class="btn btn-primary">Atualizar</button>
|
|
<a class="btn btn-outline-secondary" href="index.php">Cancelar</a>
|
|
</div>
|
|
</div></form>
|
|
</div>
|
|
<?php include __DIR__ . '/../../../includes/footer.php'; ?>
|