<?php
	include '../../autoload.php';
	
	$id=$_POST['id'];
	$type=$_POST['type'];
	if(!isset($_SESSION['language']))
		$_SESSION['language']="FR";
	$language=$_SESSION['language'];
	
	$conn = get_dbconnection();
	if ( $type == 0 )
	{
		$sql = "select quaad_point.id,level1,level2,level3,level4,level5,inlevelorder,istitle,datebeg, dateend, quaadversion, description_summary as name, description from quaad_point left join quaad_description on quaad_point.id = quaad_description.id_quaadpoint and quaad_description.language='".$language."' where quaad_point.id=".$id;
	}
	else
	{
		$sql = "select quaad_point.id,level1,level2,level3,level4,level5,inlevelorder,istitle,datebeg, dateend, quaadversion, description_summary as name, description from quaad_point left join quaad_description on quaad_point.id = quaad_description.id_quaadpoint and quaad_description.language='".$language."' where quaad_point.id=".$id;
	}
	
	error_log ( " sql : ".$sql);
	
	$answer="<quaadpoint>";
	$query = pg_query($conn,$sql);
	if($query)
	{
		if ($row = pg_fetch_row($query))
		{
			$answer.="<id>".htmlspecialchars			( $row[0], ENT_XML1, 'UTF-8' )."</id>";
			$answer.="<level1>".htmlspecialchars		( $row[1], ENT_XML1, 'UTF-8' )."</level1>";
			$answer.="<level2>".htmlspecialchars		( $row[2], ENT_XML1, 'UTF-8' )."</level2>";
			$answer.="<level3>".htmlspecialchars		( $row[3], ENT_XML1, 'UTF-8' )."</level3>";
			$answer.="<level4>".htmlspecialchars		( $row[4], ENT_XML1, 'UTF-8' )."</level4>";
			$answer.="<level5>".htmlspecialchars		( $row[5], ENT_XML1, 'UTF-8' )."</level5>";
			$answer.="<inlevelorder>".htmlspecialchars	( $row[6], ENT_XML1, 'UTF-8' )."</inlevelorder>";
			$answer.="<istitle>".htmlspecialchars		( $row[7], ENT_XML1, 'UTF-8' )."</istitle>";
			$answer.="<datebeg>".htmlspecialchars		( $row[8], ENT_XML1, 'UTF-8' )."</datebeg>";
			$answer.="<dateend>".htmlspecialchars		( $row[9], ENT_XML1, 'UTF-8' )."</dateend>";
			$answer.="<quaadversion>".htmlspecialchars	( $row[10], ENT_XML1, 'UTF-8' )."</quaadversion>";
			$answer.="<name>".htmlspecialchars			( $row[11], ENT_XML1, 'UTF-8' )."</name>";
			$answer.="<description>".htmlspecialchars	( $row[12], ENT_XML1, 'UTF-8' )."</description>";
		}
	}
	
	$answer.="</quaadpoint>";
	header('Content-Type: text/xml');
	echo $answer;
?>