<?php
require_once __DIR__ . '/../includes/bootstrap.php'; require_login(); ensure_can_manage_master_data();
$id = (int)($_GET['id'] ?? $_POST['id'] ?? 0);
if (is_post()) {
  $stmt = db()->prepare("UPDATE recruitment_vacancies SET title=?, department=?, location=?, status=?, description=? WHERE id=?");
  $stmt->execute([trim($_POST['title'] ?? ''), trim($_POST['department'] ?? ''), trim($_POST['location'] ?? ''), trim($_POST['status'] ?? 'Abierta'), trim($_POST['description'] ?? ''), $id]);
  audit_log('update','recruitment_vacancies',$id,'Vacante editada');
  set_flash('success','Vacante actualizada.'); redirect('recruitment/index.php');
}
$stmt = db()->prepare("SELECT * FROM recruitment_vacancies WHERE id=?"); $stmt->execute([$id]); $item = $stmt->fetch(); include __DIR__ . '/vacancy_form.php';
