<?php

	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		import_file(DIR_MODELS."Model.class.php");

		$id = filter_input(INPUT_POST, "id_estado", FILTER_SANITIZE_STRING);

		$model = new Model();

		$result = $model->query("SELECT * FROM cidade WHERE id_estado = :id ORDER BY id_cidade ASC", [":id" => $id]);

		if ($result->rowCount() > 0) {
			$dados = ["status" => true];

			foreach ($result->fetchAll() as $key => $value) {
				foreach ($value as $k => $v) {
					$dados["dados"][$key][$k] = $v;
				}
			}

			echo json_encode($dados);
		}
		else{
			echo json_encode(["status" => false]);
		}
	}
	else{
		show_403();
	}


?>