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

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

		$sql = "select dep_id,name as dep_name, type as combo_type, contact_acc_id as combo_contact,radiophysicist_acc_id as combo_radiophy from department where dep_id=:dep_id and removed = false";

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

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

			$d0 = $s0->fetchAll ();

			for ( $i=0; $i<count($d0); $i++ )
			{
				$res = array (	"dep_id" 			=> $d0[$i]['dep_id'],
								"name"				=> $d0[$i]['dep_name'],
								"type"				=> $d0[$i]['combo_type'],
								"contact"			=> $d0[$i]['combo_contact'],
								"radiophysicist"	=> $d0[$i]['combo_radiophy'] );

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