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

	$result = array (
			"status"	=> 'KO',
			"results"	=> array ()
	);
	
	$conn = get_dbconnection();
	
	if ( $conn )
	{
		$lang = "en";

		$sql = "select coalesce(e2.name,e1.name) as name,e1.value as value from enum_listvalue e1 left join enum_listvalue e2 on e1.lang = 'en' and e1.scope = e2.scope
		  and e2.lang ='{$lang}' and e1.value = e2.value where e1.lang = 'en' and e1.scope='{$_POST['scope']}' order by name";

		if ( $query = pg_query($conn,$sql) )
		{
			$result['status'] ='OK';

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

				array_push ( $result['results'], $res );
			}
		}
	}

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