<?php
require_once __DIR__ . '/../includes/bootstrap.php'; require_login(); ensure_can_manage_master_data();
if (is_post()) {
  $stmt = db()->prepare("INSERT INTO recruitment_applications (vacancy_id, candidate_id, stage, score, notes, applied_at, created_at) VALUES (?,?,?,?,?,?,?)");
  $stmt->execute([(int)($_POST['vacancy_id'] ?? 0), (int)($_POST['candidate_id'] ?? 0), trim($_POST['stage'] ?? 'Postulado'), (int)($_POST['score'] ?? 0), trim($_POST['notes'] ?? ''), date('Y-m-d'), now()]);
  audit_log('insert','recruitment_applications', (int)db()->lastInsertId(), 'Postulación creada');
  set_flash('success','Postulación registrada.'); redirect('recruitment/index.php');
}
$item = ['vacancy_id'=>(int)($_GET['vacancy_id'] ?? 0),'stage'=>'Postulado','score'=>0]; $action='recruitment/application_create.php'; include __DIR__ . '/application_form.php';
