<?php 

	if (Session::get("tipo_usuario") != "1"){ show_403();}
	if ($_SERVER["REQUEST_METHOD"] == "POST") {
		import_file(DIR_MODELS."Model.class.php");

		$id = encrypt_decode(filter_input(INPUT_POST, "id_compra", FILTER_SANITIZE_STRING));

		$model = new Model();

		$result = $model->query("
			SELECT * FROM distribuicao 
			WHERE 
				id_compra = :id 
			ORDER BY 
				id_distribuicao 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();
	}

?>