<?php
	include '../../autoload.php';

	error_log ( "### getpointslist ###" );
	
	$standardversion = $_REQUEST['standard_version'];
	$language='FR';
	/*if(isset($_REQUEST['language']))
		$language = $_REQUEST['language'];
	*/
	$conn = get_dbconnection();
	// $sql = "select quaad_point.id,istitle,description_summary,level2||coalesce(nullif('.'||level3,'.-1'),'')||coalesce(nullif('-'||inlevelorder,'-0'),'') from quaad_point left join quaad_description on quaad_point.id = quaad_description.id_quaadpoint  and language='".$language."' where quaadversion=".$standardVersion." order by level1,level2,level3,level4,level5,inlevelorder";
	$sql = "select quaad_point.id,istitle,description_summary, level2 || coalesce(nullif('.'||level3,'.-1'),'') || coalesce(nullif('.'||level4,'.-1'),'') || coalesce(nullif('.'||level5,'.-1'),'') || coalesce(nullif('-'||inlevelorder,'-0'),'') from quaad_point left join quaad_description on quaad_point.id = quaad_description.id_quaadpoint  and language='".$language."' where quaadversion=".$standardversion." order by level1,level2,level3,level4,level5,inlevelorder";
	
	// error_log("GetPointsList : ".$sql);
	
	$answer = "<pointslist>";
	
	$query = pg_query($conn, $sql);
	if($query)
	{
		while($row = pg_fetch_row($query))
		{

			$answer.="<point id=\"".$row[0]."\" istitle=\"".htmlspecialchars($row[1], ENT_QUOTES | ENT_XML1	)."\" description=\"".htmlspecialchars($row[2], ENT_QUOTES | ENT_XML1	)."\" level=\"".$row[3]."\"></point>";
		}
	}
	
	
	$answer.="</pointslist>";
	
	// error_log("Answer : ".$answer);
	
	header('Content-Type: text/xml');
	echo $answer;
?>