<?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_usuario", FILTER_SANITIZE_STRING));

		$model = new Model();

		$result = $model->query("
			SELECT * FROM usuario 
			WHERE 
				id_usuario = :id AND 
				status_usuario = 'S'
			", [
				":id" => $id
			]);

		if ($result->rowCount() == 1) {
			$dados = $result->fetch();

			Session::reset();
			Session::set(
				[
					"id_usuario" => $dados->id_usuario,
					"nome_usuario" => $dados->nome_usuario,
					"email_usuario" => $dados->email_usuario,
					"tipo_usuario" => $dados->id_tipo_usuario,
					"id_indicador" => $dados->id_indicador,
					"usuario_ativo" => $dados->usuario_ativo,
					"id_estado" => $dados->id_estado,
					"id_cidade" => $dados->id_cidade
				],
				[
					FILTER_SANITIZE_NUMBER_INT,
					FILTER_SANITIZE_STRING,
					FILTER_SANITIZE_EMAIL,
					FILTER_SANITIZE_NUMBER_INT,
					FILTER_SANITIZE_NUMBER_INT,
					FILTER_SANITIZE_STRING,
					FILTER_SANITIZE_NUMBER_INT,
					FILTER_SANITIZE_NUMBER_INT
				]
			);
			
			echo "<script>window.location.href='".show_link("/dashboard/?status=true")."';</script>";
		}
		else{
			echo "<script>window.location.href='".show_link("/usuarios/?status=false")."';</script>";
		}
	}
	else{
		show_403();
	}

?>