<?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_applications SET vacancy_id=?, candidate_id=?, stage=?, score=?, notes=? WHERE id=?");
  $stmt->execute([(int)($_POST['vacancy_id'] ?? 0), (int)($_POST['candidate_id'] ?? 0), trim($_POST['stage'] ?? 'Postulado'), (int)($_POST['score'] ?? 0), trim($_POST['notes'] ?? ''), $id]);
  audit_log('update','recruitment_applications',$id,'Postulación editada');
  set_flash('success','Postulación actualizada.'); redirect('recruitment/index.php');
}
$stmt = db()->prepare("SELECT * FROM recruitment_applications WHERE id=?"); $stmt->execute([$id]); $item = $stmt->fetch(); $action='recruitment/application_edit.php'; include __DIR__ . '/application_form.php';
