<?php include __DIR__ . '/../includes/header.php'; ensure_can_manage_master_data();
$id = (int)($_GET['id'] ?? 0);
$stmt = db()->prepare("SELECT * FROM leaves_requests WHERE id=?");
$stmt->execute([$id]);
$item = $stmt->fetch();
if (!$item) { set_flash('danger','Registro no encontrado.'); redirect('leaves/index.php'); }
if (is_post()) {
  $stmt = db()->prepare("UPDATE leaves_requests SET employee_id=?, leave_type=?, start_date=?, end_date=?, paid_leave=?, status=?, reason=? WHERE id=?");
  $stmt->execute([$_POST['employee_id'], $_POST['leave_type'], $_POST['start_date'], $_POST['end_date'], $_POST['paid_leave'], $_POST['status'], trim($_POST['reason']), $id]);
  audit_log('update', 'leaves_requests', $id, 'Edición permiso');
  set_flash('success', 'Permiso actualizado.');
  redirect('leaves/index.php');
}
?>
<div class="form-wrap"><h4>Editar permiso</h4><form method="post"><?php include __DIR__ . '/form.php'; ?><button class="btn btn-primary">Actualizar</button> <a class="btn btn-secondary" href="<?= e(base_url('leaves/index.php')) ?>">Volver</a></form></div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
