<?
include_once("valida_sessao.php");
protegePagina(); 
include_once("adm_head.php");

include_once("config.php");
include_once("utf8.php");

$id = stripslashes($_GET['id']);
$sql = "SELECT * FROM ctd_blocos WHERE b_id = $id";
$consulta = mysqli_query($conn, $sql);
$registro = mysqli_fetch_array($consulta);

$caminho = "../".$registro['b_arquivo'];
$conteudo = stripslashes(str_replace("´","'",$registro['b_texto']));
$conteudo = str_replace("iso-8859-1","utf-8",$conteudo);

$fp = fopen($caminho, "w"); 
$res = fwrite($fp, $conteudo , strlen($conteudo));
fclose($fp);

echo "<div id='conteudo'>";

if($res){
	$local = "ctd_bloco_adm.php?id=".$id."&alterado=1";
   	echo "<script>location.href='$local';</script>";	
}else{
	$local = "ctd_bloco_adm.php?id=".$id."&alterado=0";
   	echo "<script>location.href='$local';</script>";
}

echo "</div>";

include_once("adm_foot.php");
?>