<?php include __DIR__ . '/../includes/header.php';
$id = (int)($_GET['id'] ?? 0);
$stmt = db()->prepare("SELECT * FROM attendance WHERE id=?");
$stmt->execute([$id]);
$item = $stmt->fetch();
if (!$item) { set_flash('danger','Registro no encontrado.'); redirect('attendance/index.php'); }
if (is_post()) {
  $stmt = db()->prepare("UPDATE attendance SET employee_id=?, attendance_date=?, check_in=?, check_out=?, notes=? WHERE id=?");
  $stmt->execute([$_POST['employee_id'], $_POST['attendance_date'], $_POST['check_in'] ?: null, $_POST['check_out'] ?: null, trim($_POST['notes']), $id]);
  audit_log('update', 'attendance', $id, 'Edición asistencia');
  set_flash('success', 'Marcación actualizada.');
  redirect('attendance/index.php');
}
?>
<div class="form-wrap"><h4>Editar marcación</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('attendance/index.php')) ?>">Volver</a></form></div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
