<?php
session_start();
include("serverConnect.php");
include("functions.php");

$displayError = true;

if (isset($_GET['region'])){
    //TODO : check everything
    
    $region = intval($_GET['region']);
    
    $req = $bdd->prepare('UPDATE cRegions SET owner = ? WHERE cRegions.id = ?');
    $req->execute(array($_SESSION['id'], $region));
    
    
    $message = "Congratulations ! <br> You have annexed a new region into your glorious empire !";
    
    sendMessage($_SESSION['id'], 0, "Annexion", time(), $message);
        
    $displayError = false;
}

if (!$displayError){
	header("Location:region.php");
	exit;
}
else {
    echo "FAIL";
}
?>