<?php 
    session_start();
	if ( !empty($_SESSION['login']) ) {
        header( 'Location: /' );
        die;
	}

    include 'include/header.php';    
?>

    <div class="wrap">
<?php
    include 'include/database.php';
    
    $validated = False;
    if ( $_SERVER['REQUEST_METHOD'] === 'GET' ) {
        if ( !empty($_GET['user']) && !empty($_GET['validation']) ) {
            $connection = connect($database);
            $validated = validate_user($connection, $_GET['user'], $_GET['validation']);
            $connection = null;            
        }   
    }
    
    if ($validated) {
        echo '
            <strong class="pad center block info">
                Your account has been successfully validated!
            </strong>
            <small class="pad center block info">
                You will be redirected to login <a href="login.php">(or click here)</a>.
            </small>
        ';
        header( 'Refresh: 5; Url=login.php' );
    } else {
        echo '
            <strong class="warning center block">
                An error occured! Please contact the administrator for support.
            </strong>
        ';
    }
?>
    
    </div>

<?php include 'include/footer.php'; ?>