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

	$result = array (
			"status"	=> 'KO',
			"results"	=> array ()
	);
	
	$pdo = getPDO ();
		
	if ( $pdo )
	{
		$inst_id = -1;
		
		if ( isset($_POST['inst_id']) )		$inst_id = $_POST['inst_id'];

		$sql = "select inst_id, name as inp_name, prefix_id as inp_prefix, contact_acc_id as combo_contact,radiophysicist_acc_id as combo_radiophy, address as inp_address from institution where inst_id=:inst_id and removed = false";

		$s0 = $pdo->prepare ( $sql );

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

			$d0 = $s0->fetchAll ();

			for ( $i=0; $i<count($d0); $i++ )
			{
				$res = array (	"inst_id" 			=> $d0[$i]['inst_id'],
								"name"				=> $d0[$i]['inp_name'],
								"prefix"			=> $d0[$i]['inp_prefix'],
								"contact"			=> $d0[$i]['combo_contact'],
								"radiophysicist"	=> $d0[$i]['combo_radiophy'],
								"address"			=> $d0[$i]['inp_address'] );

				array_push ( $result['results'], $res );
			}
		}
	}
	
	header('Content-type: application/json');
	
	echo json_encode ( $result );
?>