<?php

/*
Table Game 
Unique key : 
*/

require_once("../mysql_connect.inc.php");

$authentication_key=$_POST['authentication_key'];

if ($authentication_key !== "azertyuiop") {
	// header 401, "Clé d'authentification non reconnue"
	echo "401, Clé d'authentification non reconnue\n";
}

$parameters=json_decode($_POST['parameters']);
if ( !is_array($parameters) || !is_numeric($parameters['longpollingduration']) ){
	// header 400, "Erreur"
	echo "header 400, Erreur paramètres\n";
}

$longpollingduration=$parameters['longpollingduration'];
$nbusersthreshold=$parameters['nbusersthreshold'];
$questiontimeframe=$parameters['questiontimeframe'];
$nbquestions=$parameters['nbquestions'];

if ( $parameters['flushusertable'] === "true" ) {
	$req="TRUNCATE TABLE User;"
	$res=mysql_query($req);
	//TODO check result
}

$req="INSERT INTO Game (NULL, $longpollingduration, $nbusersthreshold, $questiontimeframe, $nbquestions)";
$res=mysql_query($req);

if ( mysql_num_rows() === 1 ) {
	//TODO header 201, "OK : CREATED"
	echo "header 201, OK : CREATED\n";
} else {
	// header 400, "Erreur"
	echo "header 400, Erreur insertion SQL\n";
}
?>