<?php 

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

		$id_subcategoria_loja = (int) encrypt_decode(filter_input(INPUT_POST, "id_subcategoria_loja", FILTER_SANITIZE_STRING));
		$id_categoria_loja = (int) filter_input(INPUT_POST, "id_categoria_loja", FILTER_SANITIZE_NUMBER_INT);

		$model = new Model();

		$result = $model->update("subcategoria_loja", [
			"status_subcategoria_loja" => "N"
		], [
			"id_subcategoria_loja" => $id_subcategoria_loja
		]);

		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("/visualizar-categoria-loja/?categoria=".urlencode(encrypt_encode($id_categoria_loja))."&excluir_sub=true")."';</script>";
		}
		else{
			$model->rollback();
			echo "<script>window.location.href='".show_link("/visualizar-categoria-loja/?categoria=".urlencode(encrypt_encode($id_categoria_loja))."&excluir_sub=false")."';</script>";
		}
	}
	else{
		show_403();
	}

?>