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

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

	$type = (isset($_POST['type']))? $_POST['type'] : '';
	
	$pdo = getPDO ();
		
	if ( $pdo )
	{
		$sql = "select mail_id, enabled from alertmail where type=:type";

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

		$s0->bindParam ( 'type', $type );

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

			$d0 = $s0->fetchAll ();

			if ( count($d0) > 0 )
			{
				$res = array (	"mail_id" 	=> $d0[0]['mail_id'],
								"enabled"	=> $d0[0]['enabled'] );

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