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

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

	$pdo = getPDO ();
	
	if ( $pdo )
	{
		$s0 = $pdo->prepare ( "select department_id, staff_role_id from default_action_needed where action = :action and document_type = :document_type order by department_id" );
		$s0->bindParam ( ':action', 		$_POST["action"] );
		$s0->bindParam ( ':document_type', 	$_POST["document_type"] );

		error_log ( "Get : " .$_POST["document_type"] );

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

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

			for ( $i=0; $i<count($d0); $i++ )
			{
				error_log ( "Doc : " .$d0[$i]['department_id']. " / " .$d0[$i]['staff_role_id'] );

				array_push ( $result['results'], array ( "dep_id" => $d0[$i]['department_id'], "job_id" => $d0[$i]['staff_role_id'] ) );
			}
		}
	}





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