<?php include __DIR__ . '/../includes/header.php'; ensure_can_manage_master_data(); require_admin();
if (is_post()) {
  $stmt = db()->prepare("INSERT INTO positions (name, description, created_at) VALUES (?, ?, ?)");
  $stmt->execute([trim($_POST['name']), trim($_POST['description']), now()]);
  audit_log('create', 'positions', db()->lastInsertId(), 'Alta cargo');
  set_flash('success', 'Cargo creado.');
  redirect('positions/index.php');
}
?>
<div class="form-wrap">
  <h4>Nuevo cargo</h4>
  <form method="post">
    <div class="mb-3"><label class="form-label">Nombre</label><input name="name" class="form-control" required></div>
    <div class="mb-3"><label class="form-label">Descripción</label><textarea name="description" class="form-control"></textarea></div>
    <button class="btn btn-primary">Guardar</button>
    <a class="btn btn-secondary" href="<?= e(base_url('positions/index.php')) ?>">Volver</a>
  </form>
</div>
<?php include __DIR__ . '/../includes/footer.php'; ?>
