<?php
include_once("conexao.php");

if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['matricula'], $_POST['status'])) {
    $matricula = $_POST['matricula'];
    $status = $_POST['status']; // 'ativo' ou 'desativo'

    $stmt = $conn->prepare("UPDATE cftv SET status_matricula = ? WHERE matricula = ?");
    $stmt->bind_param("ss", $status, $matricula);
    $stmt->execute();

    if ($stmt->affected_rows > 0) {
        echo "<script>alert('Status atualizado com sucesso!'); window.location.href='update.php';</script>";
    } else {
        echo "<script>alert('Nenhuma alteração feita. Verifique o login.'); window.location.href='update.php';</script>";
    }

    $stmt->close();
} else {
    header("Location: update.php");
    exit;
}
?>
