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

	header("Content-Type: text/xml");

	$selectednrdid = '-1';
	if(isset($_POST['nrdid']))
	{
		$selectednrdid = $_POST['nrdid'];
	}

	$conn = get_dbconnection();

	$sql = "select alertname,string_agg(nrd_id::text,',') as nrd_id,bool_or(nrd_id = $1)  
	        from(
	            select distinct alert_name as alertname,nrd_id from alertwarning
	        ) as alertwarning 
	        group by alertname 
	        order by alertname";

	$query = pg_query_params($conn, $sql, array($selectednrdid));

	$arr = array();
	while( $row = pg_fetch_row($query) )
	{
		$res = array( 
	        		"id" 		=> $row [1],
	        		"name" 		=> $row [0],
	        		"selected"	=> $row [2]
	        	);

	    array_push( $arr, $res );
	}

	header('Content-type: application/json');
	
	echo json_encode($arr);
?>