<?php
	include '../../autoload.php';
	$answer ="<root>";
	$point_id =$_REQUEST['point_id'];
	$level1 =$_REQUEST['level1'];
	$level2 =$_REQUEST['level2'];
	$level3 =$_REQUEST['level3'];
	$level4 =$_REQUEST['level4'];
	$level5 =$_REQUEST['level5'];
	$orderInLevel =$_REQUEST['orderInLevel'];
	$date_begin =$_REQUEST['date_begin'];
	$date_end =$_REQUEST['date_end'];
	$quaad_version =$_REQUEST['quaad_version'];
	$isTitle =$_REQUEST['istitle'];
	
	if($point_id >= 0)
	{
		$sql = "update quaad_point set level1='".$level1."', level2='".$level2."', level3='".$level3."', level4='".$level4."', level5='".$level5."', inlevelorder='".$orderInLevel."', datebeg='".$date_begin."', dateend='".$date_end."', quaadversion=".$quaad_version.", istitle=".$isTitle." where id=".$point_id;
	}
	else
	{
		$sql = "insert into quaad_point (level1, level2, level3, level4, level5, inlevelorder, datebeg, dateend, quaadversion, istitle ) values ('".$level1."', '".$level2."', '".$level3."', '".$level4."', '".$level5."', '".$orderInLevel."', '".$date_begin."', '".$date_end."', ".$quaad_version.", ".$isTitle.") returning id";
	}

	
	$conn = get_dbconnection();
	
	$query = pg_query($conn, $sql);
	if (!$query)
	{
		$err = pg_last_error($conn);
		$answer .= "<status value=\"".$err."\"></status>";
	}
	else
	{
		$ret_id = $point_id;
		if($point_id < 0)	// Insert
		{
			$row = pg_fetch_row($query);
			$ret_id = $row[0];
		}
		$answer .= "<status value=\"ok\" id=\"".$ret_id."\"></status>";
	}
	
	$answer.="</root>";
	header('Content-Type: text/xml');
	echo $answer;
?>