<?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);

	// return $http.post('server/deleterace.php', {tier:tier, poule:poule, idchampionship:idchampionship, idteam:idteam});

	$racedelete = pg_prepare($dbconn, "racedelete", "delete from race where idrace = $1 and idchampionship = $2 and tier = $3 and poule = $4");
	$racedelete = pg_execute($dbconn, "racedelete", array($post['idrace'], $post['idchampionship'], $post['tier'], $post['poule']));

	if($racedelete===FALSE) {
		$result['ok'] = false;
		$result['error'] = pg_last_error($dbconn);
	} else {
		//return data
		$result['ok'] = true;
		$result['debug'] = 'deleted idrace '.$post['idrace'];
	}

	//print message
	$resultjson =  json_encode($result);

	echo $resultjson;
?>
