<?php
	include_once("db.php");

	//make result object
	$result = array();
	$result['ok'] = false;

	//get post data
	$postdata = file_get_contents("php://input");
	$post = json_decode($postdata, true);

	$action = $post['action'];

	if($action == 'setActiveIdRace') {
		$idrace = $post['idrace'];
		$setactiverace= pg_prepare($dbconn, "setactiverace", "update config set activerace = $1");
		$setactiverace= pg_execute($dbconn, "setactiverace", array($idrace));
	} else if($action == 'getConfig') {
		$getconfig= pg_prepare($dbconn, "getconfig", "select activerace activeidrace, tier, poule, idchampionship from config inner join race on activerace = idrace");
		$getconfig= pg_execute($dbconn, "getconfig", array());
		$result = pg_fetch_assoc($getconfig);
		//print message
		$resultjson =  json_encode($result);
		echo $resultjson;
	}
?>
