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

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

	$pdo = getPDO ();

	if ( $pdo )
	{
		$sql = "select distinct(folder) as type, folder as name from document order by folder";
		
		$s0 = $pdo->prepare ( $sql );

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

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

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