<?php
function showAlert($type, $title, $text, $redirect = null) {
    echo "<script>
        Swal.fire({
            icon: '$type',
            title: '$title',
            text: '$text',
            confirmButtonColor: '#3085d6',
            confirmButtonText: 'OK'
        })";
    
    if ($redirect) {
        echo ".then((result) => {
            if (result.isConfirmed) {
                window.location.href = '$redirect';
            }
        })";
    }
    echo ";</script>";
}

function sanitize($data) {
    global $conn;
    return htmlspecialchars(strip_tags($conn->real_escape_string($data)));
}
?>