<?php

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

		$id_categoria = (int) filter_input(INPUT_POST, "id_categoria", FILTER_SANITIZE_NUMBER_INT);

		$model = new Model();

		$result = $model->query("
			SELECT * FROM subcategoria 
			WHERE 
				id_categoria = :id AND 
				status_subcategoria = 'S'
			ORDER BY 
				nome_subcategoria ASC
		", [
			":id" => $id_categoria
		]);

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

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

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


?>