<?php

  require_once('../../../../../Config/config.php');
  require_once('../../../../../Config/odbc.php');

  $conn = get_dbconnectionRIS();

  $arr = array (
			"result"		=> 'Error',
			"users"	=> array ()
	);

	if ( $conn )
	{
		$wherecond = '';

    if(isset($_POST['type']) && $_POST['type'] != '')
		{
			$wherecond .= ' and type ='.$_POST['type'] ;
		}

		$sql = "select '' as name,-1 as use_id union select  firstname || ' ' || lastname as name, use_id from xuser where removed = false {$wherecond} order by name asc";

		if ( $query = pg_query($conn,$sql) )
		{
			while ( $row = pg_fetch_row($query) )
			{
				$arr1 = array ( "name" => $row[0], "use_id" => $row[1] );

				$arr["result"] = "OK";
				array_push ( $arr["users"], $arr1 );
			}
		}
	}

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