<?php
require_once __DIR__ . '/../includes/bootstrap.php'; require_login(); ensure_can_manage_master_data();
if (is_post()) {
  $stmt = db()->prepare("INSERT INTO recruitment_vacancies (title, department, location, status, description, created_at) VALUES (?,?,?,?,?,?)");
  $stmt->execute([trim($_POST['title'] ?? ''), trim($_POST['department'] ?? ''), trim($_POST['location'] ?? ''), trim($_POST['status'] ?? 'Abierta'), trim($_POST['description'] ?? ''), now()]);
  audit_log('insert','recruitment_vacancies', (int)db()->lastInsertId(), 'Vacante creada');
  set_flash('success','Vacante creada correctamente.'); redirect('recruitment/index.php');
}
$item = ['status'=>'Abierta']; include __DIR__ . '/vacancy_form.php';
