<?php 

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

		$status = filter_input(INPUT_POST, "status_banco", FILTER_SANITIZE_STRING);
		$id = encrypt_decode(filter_input(INPUT_POST, "id_banco", FILTER_SANITIZE_STRING));

		$model = new Model();

		$result = $model->update("banco", [
			"status_banco" => $status
		], [
			"id_banco" => $id
		]);

		if ($result > 0) {
			$last_query = $model->lastQuery();
			$model->insert("historico", [
				"comando_sql" => $last_query,
				"datahora_acao" => date("Y-m-d H:i:s"),
				"id_usuario" => Session::get("id_usuario")
			]);

			$model->commit();
			echo "<script>window.location.href='".show_link("/bancos/?status=true")."';</script>";
		}
		else{
			$model->rollback();
			echo "<script>window.location.href='".show_link("/bancos/?status=false")."';</script>";
		}
	}
	else{
		show_403();
	}

?>