<?php

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

		$id_subcategoria = (int) encrypt_decode(filter_input(INPUT_POST, "id_subcategoria", FILTER_SANITIZE_STRING));

		$model = new Model();

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

		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();
	}


?>