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

$displayError = true;

if (isset($_GET['resource']) && isset($_GET['amount']) && isset($_GET['cost'])){
    //TODO : check everything
    
    $resourceId = intval($_GET['resource']);
    $amount = intval($_GET['amount']);
    $cost = intval($_GET['cost']);
	
    $req = $bdd->prepare('INSERT INTO cTradeOffers (region, resource, amount, cost) VALUES(?, ?, ?, ?)');
    $req->execute(array($_SESSION['regionId'], $resourceId, $amount, $cost));
    
    $displayError = false;
}

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