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

	$result = array (
			"status"	=> 'KO',
			"results"	=> array ()
	);

	$type 	= -1;

	if ( isset($_POST['type']) )
		$type	= $_POST['type'];

	$type = ($type == -1)? "" : $type;


	$pdo = getPDO ();

	if ( $pdo )
	{
		$sql = "select id,status_name from statuslist where type ilike :type";
		
		$s0 = $pdo->prepare ( $sql );
		$type1 = '%'.$type.'%';
		$s0->bindParam ( ":type", $type1 );

		if ( $s0->execute () )
		{
			$result ['status'] = 'OK';

			$d0 = $s0->fetchAll ( PDO::FETCH_ASSOC );

			for ( $i=0; $i<count ( $d0 ); $i++ )
				array_push ( $result['results'], array ( 	'id' 	=> $d0[$i]['id'],
															'name'	=> $d0[$i]['status_name'] ) );
		}
	}
	
	header('Content-type: application/json');
	
	echo json_encode ( $result );
?>