<?php include __DIR__ . '/../includes/header.php';
if (is_post()) {
  $stmt = db()->prepare("INSERT INTO leaves_requests (employee_id, leave_type, start_date, end_date, paid_leave, status, reason, created_at) VALUES (?, ?, ?, ?, ?, ?, ?, ?)");
  $stmt->execute([$_POST['employee_id'], $_POST['leave_type'], $_POST['start_date'], $_POST['end_date'], $_POST['paid_leave'], $_POST['status'], trim($_POST['reason']), now()]);
  audit_log('create', 'leaves_requests', db()->lastInsertId(), 'Alta permiso');
  set_flash('success', 'Permiso guardado.');
  redirect('leaves/index.php');
}
$item = [];
?>
<div class="form-wrap"><h4>Nuevo permiso</h4><form method="post"><?php include __DIR__ . '/form.php'; ?><button class="btn btn-primary">Guardar</button> <a class="btn btn-secondary" href="<?= e(base_url('leaves/index.php')) ?>">Volver</a></form></div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
