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

	$document_scope 		= (isset($_GET['document_scope']))? $_GET['document_scope'] : "";
		
	$conn = get_dbconnection();
	
	$answer = "<tags>";
	
	if ( $conn )
	{
		/*
		$sql ="select quaadpoint_tag.id, quaadpoint_tag_name.name, audit_type.name as type, document_scope from audit_type,quaadpoint_tag,quaadpoint_tag_name,quaad_point , link_quaad_tag  where quaadpoint_tag.id=quaadpoint_tag_name.id_quaadpoint_tag and link_quaad_tag.id_quaadpoint=quaad_point.id and link_quaad_tag.id_tag= quaadpoint_tag.id and audit_type.id=quaad_point.quaadversion and document_scope='".$document_scope."' and language='FR'  order by type,id;";
		*/

		// $whereclause = ( strlen($document_scope)>0 ) ? "and document_scope='".$document_scope."'" : "";

		$whereclause = "";

		if ( $document_scope != 'procedure')
			$whereclause = "and document_scope='".$document_scope."'";

		$sql ="select quaadpoint_tag.id, quaadpoint_tag_name.name, audit_type.name as type, document_scope from audit_type,quaadpoint_tag,quaadpoint_tag_name,quaad_point , link_quaad_tag  where quaadpoint_tag.id=quaadpoint_tag_name.id_quaadpoint_tag and link_quaad_tag.id_quaadpoint=quaad_point.id and link_quaad_tag.id_tag= quaadpoint_tag.id and audit_type.id=quaad_point.quaadversion ".$whereclause." and language='FR'  order by type,name;";

		error_log ("get_bquaad_tag : " .$sql );
		

		if ( $query = pg_query($conn,$sql) )
		{
			while ( $row = pg_fetch_row($query) )
			{
				$answer .= "<tag id=\"".$row[0]."\" name=\"".$row[1]."\" type=\"".$row[2]."\" scope=\"".$row[3]."\"></tag>";
			}
		}
	}
	
	$answer .= "</tags>";

	header ('Content-type: text/xml' );
	
	echo $answer;
?>